﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HanGu.Services.Interface;
using HanGu.Entity;

namespace HanGu.Services
{
    public class ChangeGradeRecordeService : BaseService, IChangeGradeRecorde
    {

        public List<VChangeGradeRecorde> GetAll(UniversallySearchParam searchParam)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {

                var query = obj.VChangeGradeRecorde.Where(c=>1==1);
                if (searchParam.IntObj1 != 0)
                {
                    query = query.Where(c => c.VIPID == searchParam.IntObj1);
                }
                if (searchParam.StarDateTime.HasValue)
                {
                    query = query.Where(c => c.ChangeTime >= searchParam.StarDateTime);
                }
                if (searchParam.EndDateTime.HasValue)
                {
                    query = query.Where(c => c.ChangeTime <= searchParam.EndDateTime);
                }
                return base.Paging<VChangeGradeRecorde, DateTime?>(c => c.ChangeTime, query, searchParam.Pagination).ToList();
            }
        }

        public List<ChangeGradeRecorde> GetByID(int id)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                List<ChangeGradeRecorde> list = null;
                if (id > 0)
                {
                    list = obj.ChangeGradeRecorde.Where(c => c.VIPID == id).OrderByDescending(c => c.ChangeTime).ToList();
                }
                else
                {
                    list = obj.ChangeGradeRecorde.OrderByDescending(c => c.ChangeTime).ToList();
                }
                return list;
            }
        }


        public bool Add(ChangeGradeRecorde model)
        {
            try
            {
                this.Add<ChangeGradeRecorde>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Update(ChangeGradeRecorde model)
        {
            try
            {
                this.Update<ChangeGradeRecorde>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Delete(int id)
        {
            try
            {
                this.Delete<ChangeGradeRecorde>(c => c.ID == id);
                return true;
            }
            catch { return false; }
        }


    }
}
